//
//  TMGProductTableViewCell.m
//  TMGold
//
//  Created by Mac on 2017/11/9.
//  Copyright © 2017年 tangmu. All rights reserved.
//

#import "TMGCategoryListTableViewCell.h"
#define monthColor  [UIColor colorWithRed:62/255.0 green:130/255.0 blue:277.0/255.0 alpha:1]
@interface TMGCategoryListTableViewCell()
@property(nonatomic, strong) STButton                     *titleButton;
@property(nonatomic, strong) STLabel                     *yearPecetLabel;
@property(nonatomic, strong) STLabel                     *timeLabel;
@property(nonatomic, strong) STLabel                     *moneyLabel;
@end
@implementation TMGCategoryListTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self configSubView];
    }
    return self;
}
+ (CGFloat)cellHeight{
    return 125;
}
#pragma mark --subView
- (void)configSubView{
    
    self.backgroundColor = [UIColor whiteColor];
    
    self.titleButton = [[STButton alloc] initWithFrame:CGRectMake(10, 0, 200, 44)
                                                 title:@"流动金"
                                            titleColor:TM_firstTextColor
                                             titleFont:14
                                          cornerRadius:0
                                       backgroundColor:nil
                                       backgroundImage:nil
                                                 image:nil];
    self.titleButton.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    [self addSubview:self.titleButton];
    self.titleButton.centerY = 22;
    
    STButton * iconButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)
                                                      title:nil
                                                 titleColor:nil
                                                  titleFont:0
                                               cornerRadius:0
                                            backgroundColor:nil
                                            backgroundImage:nil
                                                      image:[UIImage imageNamed:@"sy_箭头02"]];
    [self addSubview:iconButton];
    iconButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    iconButton.right = UIScreenWidth - 15;
    
    UIView * line = [[UIView alloc] initWithFrame:CGRectMake(10, iconButton.bottom, UIScreenWidth - 20, 0.5)];
    line.backgroundColor = TM_lineColor;
    [self addSubview:line];
    
    
    self.yearPecetLabel = [[STLabel alloc] initWithFrame:CGRectMake(10, line.bottom  +10 , UIScreenWidth/2, 30)
                                                    text:@"7~8%"
                                               textColor:TM_orangeColor
                                                    font:22
                                             isSizetoFit:NO
                                           textAlignment:NSTextAlignmentLeft];
    [self addSubview:self.yearPecetLabel];
    
    self.timeLabel = [[STLabel alloc] initWithFrame:CGRectMake(self.yearPecetLabel.right, self.titleButton.bottom , UIScreenWidth/2, 30)
                                               text:@"买入期限 6~345天"
                                          textColor:TM_firstTextColor
                                               font:14
                                        isSizetoFit:NO
                                      textAlignment:NSTextAlignmentRight];
    self.timeLabel.attributedText = [self.timeLabel.text st_convertAttributeStringWithKeyWord:@"买入期限" attributes:@{NSForegroundColorAttributeName:TM_secendTextColor}];
    self.timeLabel.right = UIScreenWidth - 15;
    [self addSubview:self.timeLabel];
    
    STLabel * yearLable = [[STLabel alloc] initWithFrame:CGRectMake(10, self.yearPecetLabel.bottom, UIScreenWidth / 2, 16)
                                                    text:@"预期黄金收益率"
                                               textColor:TM_secendTextColor
                                                    font:14
                                             isSizetoFit:NO
                                           textAlignment:NSTextAlignmentLeft];
    
    [self addSubview:yearLable];
    
    self.moneyLabel = [[STLabel alloc] initWithFrame:CGRectMake(self.yearPecetLabel.right, self.yearPecetLabel.bottom, UIScreenWidth / 2, 16)
                                                text:@"起购金额  1元起投"
                                           textColor:TM_firstTextColor
                                                font:14
                                         isSizetoFit:NO
                                       textAlignment:NSTextAlignmentRight];
    self.moneyLabel.attributedText = [self.moneyLabel.text st_convertAttributeStringWithKeyWord:@"起购金额" attributes:@{NSForegroundColorAttributeName:TM_secendTextColor}];
    self.moneyLabel.right = UIScreenWidth - 15;
    [self addSubview:self.moneyLabel];
    
    
    UIView * grawView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 10)];
    grawView.backgroundColor = TM_backgroundColor;
    grawView.bottom = 125;
    [self addSubview:grawView];
}
- (void)setModel:(TMGProductModel *)model{
    _model = model;
    
    [self.titleButton setTitle:model.name forState:UIControlStateNormal];
    NSString * rate = self.model.year_rate_from;
    if (self.model.year_rate_to.floatValue > 0.1) {
        rate = [NSString stringWithFormat:@"%@~%@",self.model.year_rate_from,self.model.year_rate_to];
    }
    rate = [NSString stringWithFormat:@"%@%%",rate];
    
    self.yearPecetLabel.text = rate;
    
    self.moneyLabel.text = [NSString stringWithFormat:@"起购金额  %@元起购",
                            @(model.buy_start.integerValue)];
    self.moneyLabel.attributedText = [self.moneyLabel.text st_convertAttributeStringWithKeyWord:@"起购金额" attributes:@{NSForegroundColorAttributeName:TM_secendTextColor}];
    
    if (model.cate.integerValue == 6) {
         self.timeLabel.text = [NSString stringWithFormat:@"买入期限  %@月",model.day_number.description];
        [self.titleButton setTitleColor:monthColor forState:UIControlStateNormal];
    }else{
        self.timeLabel.text = [NSString stringWithFormat:@"买入期限  %@天",model.day_number.description];
        [self.titleButton setTitleColor:TM_firstTextColor forState:UIControlStateNormal];
    }
    if (model.day_number.integerValue < 1) {
      self.timeLabel.text = [NSString stringWithFormat:@"买入期限  %@",@"随时买卖"];
    }
//    self.moneyLabel.text = [NSString stringWithFormat:@"起购金额  %@",@"1元起购"];
    
}
@end

